home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
-
- try:
- import zlib
- except ImportError:
- zlib = None
-
- import zipfile
- import os
- import unittest
- from StringIO import StringIO
- from tempfile import TemporaryFile
- from test.test_support import TESTFN, run_unittest
- TESTFN2 = TESTFN + '2'
-
- class TestsWithSourceFile(unittest.TestCase):
-
- def setUp(self):
- line_gen = (lambda [outmost-iterable]: for i in [outmost-iterable]:
- 'Test of zipfile line %d.' % i)(range(0, 1000))
- self.data = '\n'.join(line_gen)
- fp = open(TESTFN, 'wb')
- fp.write(self.data)
- fp.close()
-
-
- def zipTest(self, f, compression):
- zipfp = zipfile.ZipFile(f, 'w', compression)
- zipfp.write(TESTFN, 'another' + os.extsep + 'name')
- zipfp.write(TESTFN, TESTFN)
- zipfp.close()
- zipfp = zipfile.ZipFile(f, 'r', compression)
- self.assertEqual(zipfp.read(TESTFN), self.data)
- self.assertEqual(zipfp.read('another' + os.extsep + 'name'), self.data)
- zipfp.close()
-
-
- def testStored(self):
- for f in (TESTFN2, TemporaryFile(), StringIO()):
- self.zipTest(f, zipfile.ZIP_STORED)
-
-
- if zlib:
-
- def testDeflated(self):
- for f in (TESTFN2, TemporaryFile(), StringIO()):
- self.zipTest(f, zipfile.ZIP_DEFLATED)
-
-
-
-
- def tearDown(self):
- os.remove(TESTFN)
- os.remove(TESTFN2)
-
-
-
- class OtherTests(unittest.TestCase):
-
- def testCloseErroneousFile(self):
- fp = open(TESTFN, 'w')
- fp.write('this is not a legal zip file\n')
- fp.close()
-
- try:
- zf = zipfile.ZipFile(TESTFN)
- except zipfile.BadZipfile:
- os.unlink(TESTFN)
-
-
-
- def testNonExistentFileRaisesIOError(self):
- self.assertRaises(IOError, zipfile.ZipFile, TESTFN)
-
-
- def testClosedZipRaisesRuntimeError(self):
- data = StringIO()
- zipf = zipfile.ZipFile(data, mode = 'w')
- zipf.writestr('foo.txt', 'O, for a Muse of Fire!')
- zipf.close()
- self.assertRaises(RuntimeError, zipf.testzip)
-
-
-
- def test_main():
- run_unittest(TestsWithSourceFile, OtherTests)
-
- if __name__ == '__main__':
- test_main()
-
-